package com.shengyuan.manage_os.old.ying.erpm;

import java.util.ArrayList;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.old.ying.erpm.controls.CurrentPersonal;
import com.shengyuan.manage_os.old.ying.erpm.db.Actual_ErpUser;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;

public class Actual_OA_ShangBanDengJi extends PreferenceActivity {

	SharedPreferences  sp;
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.shangbandengji);
		Actual_ErpUser erpUser = new Actual_ErpUser(this);
		ArrayList<String> arrayList = erpUser.getAllUserName();
		
		if (arrayList.size() > 0) {
			CharSequence[] entries = new CharSequence[arrayList.size()] ;
			for (int i = 0; i < entries.length; i++) {
				entries[i] = arrayList.get(i);
			}
			ListPreference lp = (ListPreference)findPreference("shangbandengji_selectren");
			lp.setEntries(entries);
			lp.setEntryValues(entries);
			
		}

		sp = PreferenceManager.getDefaultSharedPreferences(this); 
		sp.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener(){   
			  
			@Override  
			//sharedPreferences:句柄   
			//key: 改变 键值   
			public void onSharedPreferenceChanged(   
			SharedPreferences sharedPreferences, String key) {   
			// TODO Auto-generated method stub   
			  
			if(key.equals("shangbandengji_selectren")){   
			String autoBack = sharedPreferences.getString("shangbandengji_selectren", "");   
			}
			}});  

	}

	@Override
	@Deprecated
	public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
			Preference preference) {
		if (preference.getKey().equals("DengJiTime1") || preference.getKey().equals("DengJiTime2")) {
			SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
			String value = sharedPreferences.getString("shangbandengji_selectren", LoginActivity.pmUser.UserName);
			CurrentPersonal.UserName = value;
			Actual_OA_DaKa.DengJi = preference.getKey();
			Intent intent = new Intent( this, Actual_OA_DaKa.class);
			this.startActivity(intent);
		}else if(preference.getKey().equals("shangbandengji_selectren")) {
			
		}
		return super.onPreferenceTreeClick(preferenceScreen, preference);
		
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

}
